public class Test24 {
    public static void main(String[] args) {
        MyStack m =new MyStack();//创建对象，栈
        for (int i = 0; i < 11; i++) {//压栈
            m.push(new MyStack());//传入方法，模拟压栈过程
        }
        for (int j = 0; j < 10; j++) {//弹栈
            m.pop(null);//传入空，模拟弹栈过程
        }
    }
}
class MyStack{
    //实例对象
    private Object[]elements;//栈数组
    private int inde;//栈帧
    //无，有参构造
    public MyStack() {
        this.elements =new Object[10];
        this.inde = -1;
    }
    public MyStack(Object[] elements,int inde) {
        this.elements = elements;
        this.inde = inde;
    }
    //栈数组读写入口
    public Object[] getElements() {
        return elements;
    }
    public void setElements(Object[] elements) {
        this.elements = elements;
    }
    //栈帧读写入口
    public int getInde() {
        return inde;
    }
    public void setInde(int inde) {
        this.inde = inde;
    }
    //压栈方法
    public void push(Object obj){
        if (this.inde >= 9){//栈帧最多指十个元素（最长下标为9）
            System.out.println("压栈失败，本栈已满");
            return;
        }
        this.inde++;//栈帧上移
        this.elements[inde] =obj;//压栈
        System.out.println("压栈成功，栈帧指向"+inde);
    }
    //弹栈方法
    public void pop(Object obj){
        inde--;//栈帧下移
        if (this.inde < 0){//栈帧最低到栈底
            System.out.println("本栈已空");
            return;
        }
        this.elements[inde] =obj;//弹栈
        System.out.println("弹栈成功，栈帧指向"+inde);
    }
}